package fw.protocol.zigbee.bundle;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

import es.unizar.howlab.core.io.serial.SerialConnection;
import es.unizar.howlab.core.io.serial.SerialConnectionConfig.Protocol;
import es.unizar.howlab.core.io.serial.logic.SerialDriver;

public class SerialDriverManager implements ServiceTrackerCustomizer {

	private BundleContext bc;
	private SerialConnectionManager scm = new SerialConnectionManager();
	
	public SerialDriverManager(BundleContext bc) {
		this.bc = bc;
	}
	
	public Object addingService(ServiceReference sf) {
		SerialDriver sd = (SerialDriver) bc.getService(sf);
		SerialConnection sc = sd.newSerialConnection(Protocol.rs232,  "COM4", "19200");
		scm.sendDeviceMessage(sc);
		return sd;
	}

	public void modifiedService(ServiceReference arg0, Object arg1) {
		// TODO Auto-generated method stub
		
	}

	public void removedService(ServiceReference arg0, Object arg1) {
		// TODO Auto-generated method stub
		
	}

}
